Skip to content

Conversation

Copy link

Copilot AI commented Jan 31, 2026

Hardcoded os.path.dirname(__file__) paths fail in PyInstaller --onefile builds because __file__ points to source locations, not the temporary _MEIPASS extraction folder. This breaks ONNX model loading and config file access at runtime.

Changes

Core implementation

  • Added resource_path() to src/utils/resource_manager.py that detects sys._MEIPASS and returns correct paths for both development and frozen modes
  • Exported from src/utils/__init__.py

Model loading updates

  • Updated 7 DLNode files to use resource_path() for all ONNX model paths:
    • node_classification.py (5 models)
    • node_object_detection.py (7 models)
    • node_semantic_segmentation.py (4 models)
    • node_pose_estimation.py (3 models)
    • node_face_detection.py (1 model)
    • node_low_light_image_enhancement.py (6 models)
    • node_monocular_depth_estimation.py (4 models)
  • Fixed node/DLNode/object_detection/YOLOX/yolox.py to load coco_classes.txt using resource_path()

Documentation

  • Added verification script verify_pyinstaller_portability.py
  • Added English and French documentation

Example

Before:

_model_base_path = os.path.dirname(os.path.abspath(__file__)) + '/classification/'
model_path = _model_base_path + 'MobileNetV3/model/MobileNetV3Small.onnx'
# Fails in PyInstaller: points to source location, not _MEIPASS

After:

from src.utils import resource_path
model_path = resource_path('node/DLNode/classification/MobileNetV3/model/MobileNetV3Small.onnx')
# Works in both dev and frozen modes

The function automatically resolves to sys._MEIPASS when frozen, or project root in development. All 20+ ONNX models now load correctly in PyInstaller executables.

Original prompt

Mission : Audit de portabilité pour PyInstaller --onefile.

Contexte : J'ai un projet Python avec une structure complexe (node/, node_editor/, src/). Je vais te donner mon code. Je veux que tu vérifies chaque accès aux fichiers (fichiers JSON, modèles ONNX, polices, images).

Tâches attendues :

Identifie toutes les lignes où j'utilise des chemins relatifs (ex: open("node_editor/...") ou os.path.join("node", ...)).

Propose-moi l'intégration de la fonction resource_path suivante pour gérer le dossier temporaire _MEIPASS :

Python

def resource_path(relative_path):
import sys, os
base_path = getattr(sys, '_MEIPASS', os.path.abspath("."))
return os.path.join(base_path, relative_path)
Réécris les lignes d'accès aux fichiers en utilisant resource_path().

Vérifie spécifiquement le chargement des modèles ONNX dans node/DLNode pour m'assurer qu'ils pointeront bien vers le dossier interne de l'exécutable.


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI and others added 6 commits January 31, 2026 00:37
…r compatibility

Co-authored-by: hackolite <826027+hackolite@users.noreply.github.com>
Co-authored-by: hackolite <826027+hackolite@users.noreply.github.com>
Co-authored-by: hackolite <826027+hackolite@users.noreply.github.com>
Co-authored-by: hackolite <826027+hackolite@users.noreply.github.com>
Co-authored-by: hackolite <826027+hackolite@users.noreply.github.com>
Co-authored-by: hackolite <826027+hackolite@users.noreply.github.com>
Copilot AI changed the title [WIP] Audit file access in Python project for portability Add PyInstaller --onefile support via centralized resource_path() Jan 31, 2026
Copilot AI requested a review from hackolite January 31, 2026 00:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants